<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('POS终端信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 130px">品牌名称：</label>
                                <select name="manuNum" >
                                    <option value="">选择品牌</option>
                                    <option th:each="m:${manufacturer}" th:text="${m.MANU_NAME}" th:value="${m.MANU_NUM}"></option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 130px">活动编号：</label>
                                <input type="text" name="actId"/>
                            </li>
                            <li>
                                <label style="width: 130px">活动名称：</label>
                                <input type="text" name="actName"/>
                            </li>
                            <li>
                                <label style="width: 130px;">终端所属代理名称：</label>
                                <input type="text" name="agentName"/>
                            </li>
                            <li>
                                <label style="width: 130px;">终端所属代理编号：</label>
                                <input type="text" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" name="agentNum"/>
                            </li>
                            <li>
                                <label style="width: 130px;">结算人姓名：</label>
                                <input type="text" name="screenName"/>
                            </li>
                            <li>
                                <label style="width: 130px;">终端类型：</label>
                                <select name="posType" th:with="type=${@dict.getType('terminal_type')}">
                                    <option value="">请选择</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 130px;">开通状态：</label>
                                <select name="isbound">
                                    <option value="">请选择</option>
                                    <option value="1">已开通</option>
                                    <option value="0">未开通</option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 130px;">是否激活：</label>
                                <select name="activate">
                                    <option value="">请选择</option>
                                    <option value="2">否</option>
                                    <option value="1">是</option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 130px;">是否伪激活：</label>
                                <select name="is_wei">
                                    <option value="">请选择</option>
                                    <option value="0">否</option>
                                    <option value="1">是</option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 130px;">达标阶段：</label>
                                <select name="is_day_stage" th:with="type=${@dict.getType('stage')}">
                                    <option value="">请选择</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                          <!--  <li>
                                <label style="width: 130px;">终端来源：</label>
                                <select name="dqType">
                                    <option value="">请选择</option>
                                    <option value="1">划拨机</option>
                                    <option value="2">自购机</option>
                                </select>
                            </li>-->
                            <li class="select-time">
                                <label style="width: 130px;">开通时间：</label>
                                <input type="text" class="time-input" value=""  id="startTime" placeholder="开始日期" name="params[beginAddTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" value="" id="endTime" placeholder="结束日期" name="params[endAddTime]"/>
                            </li>
                            <li class="select-time">
                                <label style="width: 130px;">激活时间：</label>
                                <input type="text" class="time-input" id="startTime1" placeholder="开始日期" name="params[beginAddTime1]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime1" placeholder="结束日期" name="params[endAddTime1]"/>
                            </li>
                          <!--  <li class="select-time">
                                <label style="width: 130px;">达标日期：</label>
                                <input type="text" class="time-input" id="startTime2" placeholder="开始日期" name="params[beginAddTime2]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endAddTime2" placeholder="结束日期" name="params[endAddTime2]"/>
                            </li>-->
                            <li>
                                <label style="width: 130px;">商户编号：</label>
                                <input type="text" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" name="merno"/>
                            </li>
                           <!-- <li>
                                <label style="width: 130px;">返现周期：</label>
                                <select name="recurrenceCycle">
                                    <option value="">请选择</option>
                                    <option value="0">日返</option>
                                    <option value="1">月返</option>
                                </select>
                            </li>-->
                            <li>
                                <label style="width: 130px;">SN编号起止号段：</label>
                                <input type="text" name="params[start_sn]"   style="width: 130px">-<input type="text" name="params[end_sn]"  style="width: 130px">
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>

                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 search-collapse">
                <span style="color:blue">[</span>
                <span style="color: blue;font-style: initial">参与活动：</span>
                <span id="act_count" style="color: red;font-style: initial">0</span><span style="color: blue;font-style: initial"> 个</span>
                <span style="color:blue">]</span>
                <span style="color:blue">[</span>
                <span style="color: blue;font-style: initial">激活台数：</span>
                <span id="yes_activate" style="color: red;font-style: initial">0</span><span style="color: blue;font-style: initial"> 台</span>
                <span style="color:blue">]</span>
                <span style="color:blue">[</span>
                <span style="color: blue;font-style: initial">未激活台数：</span>
                <span id="not_activate" style="color: red;font-style: initial">0</span><span style="color: blue;font-style: initial"> 台</span>
                <span style="color:blue">]</span>
                <span style="color:blue">[</span>
                <span style="color: blue;font-style: initial">伪激活台数：</span>
                <span id="yes_wei" style="color: red;font-style: initial">0</span><span style="color: blue;font-style: initial"> 台</span>
                <span style="color:blue">]</span>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
               <!-- <a class="btn btn-success" onclick="onchagePosSource()" shiro:hasPermission="formalPos:formalPos:onchagePosSource">
                    <i class="fa fa-edit"></i> 变更终端来源
                </a>-->
                <a class="btn btn-success" onclick="onchagePosAct()" shiro:hasPermission="formalPos:formalPos:onchagePosAct">
                    <i class="fa fa-edit"></i> 变更活动到期日
                </a>
                <!--<a class="btn btn-success" onclick="purchaser()" shiro:hasPermission="formalPos:formalPos:updatePurchaser">
                    <i class="fa fa-edit"></i> 批量变更购买人
                </a>-->
                <a class="btn btn-success" onclick="activity()" shiro:hasPermission="formalPos:formalPos:updateActivityBatch">
                    <i class="fa fa-edit"></i> 活动批量切换
                </a>
                <a class="btn btn-success" onclick="returnObj()" shiro:hasPermission="formalPos:formalPos:updateActivityReturn">
                    <i class="fa fa-edit"></i> 变更返现对象
                </a>
                <a class="btn btn-success" onclick="batchReturnObj()" shiro:hasPermission="formalPos:formalPos:updateActivityReturnBatch">
                    <i class="fa fa-edit"></i> 批量变更返现对象
                </a>
                <a class="btn btn-success" onclick="downloadaAct()" shiro:hasPermission="terminal:record:downloada">
                    <i class="fa fa-plus"></i> 活动变更模板下载
                </a>

                <a class="btn btn-warning" onclick="ybExport()" shiro:hasPermission="formalPos:formalPos:ybExport">
                    <i class="fa fa-download"></i> 导出
                </a>


            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" class="table text-nowrap"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "formalPos/formalPos";
        var unbundlingMposFlag = [[${@permission.hasPermi('formalPos:formalPos:unbundlingMpos')}]];
        var terminalTypeDatas = [[${@dict.getType('terminal_type')}]];
        var stage = [[${@dict.getType('stage')}]];
        $(function() {
            var options = {
                url: prefix + "/ybList",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "已绑定机具",
                firstLoad:true,
                responseHandler:responseHandler,
                clickToSelect:true,
                columns: [
                    {
                        radio: true
                    },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'posno',
                    title: 'POS编号'
                },
                {
                    field: 'machineNum',
                    title: 'SN编号'
                },
                {
                    field: 'agentNum',
                    title: '终端所属代理编号'
                },
                {
                    field: 'agentName',
                    title: '终端所属代理名称'
                },
                {
                    field: 'posType',
                    title: '终端类型',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(terminalTypeDatas, value);
                    },
                },
                {
                    field: 'pos_version',
                    title: '机器版本',
                    formatter: function (value, row, index) {
                        if (row.pos_version == 1 ){
                            return '<span style="color: red">1.0</span>';
                        } else if(row.pos_version == 2 ){
                            return '<span style="color: blue">2.0</span>';
                        }
                    },
                },
                {
                    field: 'actId',
                    title: '活动编号'
                },
                {
                    field: 'actName',
                    title: '活动名称'
                },
                {
                    field: 'actEnd',
                    title: '活动截止日期'
                },
                {
                    field: 'isbound',
                    title: '开通状态',
                    formatter: function (value, row, index) {
                        if (value == 0 ){
                            return '<span style="color: blue">未开通</span>';
                        } else if(value == 1 ){
                            return '<span style="color: green">已开通</span>';
                        } else {
                            return '<span style="color: red">未知</span>';
                        }
                    },
                    sortable: true
                },
                    {
                        field: 'activate',
                        title: '是否激活',
                        formatter: function (value, row, index) {
                            if (value == 1 ){
                                return '<span style="color: blue">是</span>';
                            } else if(value == 2 ){
                                return '<span style="color: green">否</span>';
                            } else {
                                return '<span style="color: red">未知</span>';
                            }
                        },
                        sortable: true
                    },
                    {
                        field: 'is_wei',
                        title: '是否伪激活',
                        formatter: function (value, row, index) {
                            if (value == 0 ){
                                return '<span style="color: blue">否</span>';
                            } else if(value == 1 ){
                                return '<span style="color: green">是</span>';
                            } else {
                                return '<span style="color: red">未知</span>';
                            }
                        },
                        sortable: true
                    },
                {
                    field: 'is_day_stage',
                    title: '达标阶段',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(stage, value);
                    },
                },
              /*  {
                    field: 'achievementDate',
                    title: '达标日期'
                },*/
              /*  {
                    field: 'achievementMoney',
                    title: '达标金额',
                    formatter: function (value, row, index) {
                        return $.table.rmbFormatter(value);
                    }
                },*/
                {
                    field: 'simFee',
                    title: '流量费'
                },
                {
                    field: 'simEnd',
                    title: '流量费收取天数'
                },
                {
                    field: 'service_fee',
                    title: '服务费'
                },
                {
                    field: 'service_end',
                    title: '服务费收取天数'
                },
                /*{
                    field: 'branchPos.serviceAgentNum',
                    title: '服务费返现对象'
                },*/
             /*   {
                    field: 'returnDate',
                    title: '应返现日期'
                },*/
               /* {
                    field: 'returnMoney',
                    title: '返现金额',
                    formatter: function (value, row, index) {
                        return $.table.rmbFormatter(value);
                    }
                },*/
               /* {
                    field:'recurrenceCycle',
                    title: '返现周期',
                    formatter: function (value, row, index) {
                        if (value == 0 ){
                            return '<span style="color: blue">日返</span>';
                        } else if(value == 1 ){
                            return '<span style="color: green">月返</span>';
                        } else {
                            return '<span style="color: red">未知</span>';
                        }
                    },
                    sortable: true
                },*/

                /*{
                    field: 'directlyUnderAgentno',
                    title: '终端所属代理编号'
                },*/
             /*   {
                    field: 'buyerNum',
                    title: '购买人'
                },*/
                /*{
                    field: 'dqType',
                    title: '终端来源',
                    formatter:function (value) {
                        if (value == '1'){
                            return '<span style="color: blue">划拨机</span>';
                        } else if (value == '2'){
                            return '<span style="color: green">自购机</span>';
                        }
                    }
                },*/
                {
                    field: 'screenName',
                    title: '结算人名'
                },
                {
                    field: 'merno',
                    title: '商户编号'
                },

                {
                    field: 'createdate',
                    title: '开通时间'
                },
                /*{
                    field: 'proYlId',
                    title: '购买人奖励返现对象'
                },*/
                {
                    field: 'updateMan',
                    title: '变更人'
                },
               /* {
                    field: 'buyMoney',
                    title: '采购人奖励'
                },*/
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                                actions.push('<a class="btn btn-success btn-xs ' + unbundlingMposFlag + '" href="javascript:void(0)" onclick="unbundlingMpos(\'' + row.posno + '\',\''+row.merno+'\')"><i class="fa fa-edit"></i>解绑终端</a> ');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        });

        function responseHandler(res) {
            $("#act_count").text(res.data.ACT_COUNT);
            $("#yes_activate").text(res.data.YES_ACTIVATE);
            $("#not_activate").text(res.data.NOT_ACTIVATE);
            $("#yes_wei").text(res.data.YES_WEI);

        }



        function unbundlingMpos(posno,merno) {
            $.modal.confirm("确认要解绑"+posno+"终端吗?", function() {
                var data = { "posno": posno ,"merno":merno};
                $.operate.submit(prefix+"/unbundlingMpos", "post", "json", data);
            });
        }
        // 导出数据
        function ybExport(formId) {
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            $.modal.confirm("确定导出" + table.options.modalName + "吗？", function() {
                var url = prefix + '/ybExport';
                var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
                var params = $("#" + table.options.id).bootstrapTable('getOptions');
                var dataParam = $("#" + currentId).serializeArray();
                dataParam.push({ "name": "orderByColumn", "value": params.sortName });
                dataParam.push({ "name": "isAsc", "value": params.sortOrder });
                $.modal.loading("正在导出数据，请稍后...");
                $.post(url, dataParam, function(result) {
                    if (result.code == web_status.SUCCESS) {
                        window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    } else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                });
            });
        }


        /**
         * 变更终端来源
         */
        function onchagePosSource() {
            var posno = $.table.selectColumns("posno");
            $.modal.open("变更终端来源", prefix + "/onchagePosSource/" + posno, '850', '550');
        }
        /**
         * 变更终端活动到期日
         */
        function onchagePosAct() {
            var posno = $.table.selectColumns("posno");
            if ($.common.isEmpty(posno)){
                $.modal.msgWarning("请选择一条数据");
                return false;
            }
            $.modal.open("变更终端活动到期日", prefix + "/onchagePosAct/" + posno, '850', '550');
        }

        /**
         * 批量变更购买人
         */
        function purchaser(){
            $.modal.open("批量变更购买人", prefix + "/updatePurchaser/", '850', '550');
        }

        /**
         * 批量变更活动
         */
        function activity(){
            $.modal.open("批量变更活动", prefix + "/updateActivity/", '850', '550');
        }
        /**
         * 返现对象变更
         */
        function returnObj(){
            var posno = $.table.selectColumns("posno");
            if ($.common.isEmpty(posno)){
                $.modal.msgWarning("请选择一条数据");
                return false;
            }
            $.modal.open("返现对象变更", prefix + "/returnObj/" + posno, '1300', '550');
        }
        function batchReturnObj(){
            $.modal.open("批量变更返现对象", prefix + "/batchReturnObj", '1300', '650');
        }

        function downloadaAct() {
            table.set();
            $.get(prefix+"/exportFileAct", function(result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
            });
        }

    </script>
</body>
</html>
